<template>
    <div class="container">
        <div class="card">
          <el-breadcrumb separator="/" class="card-body">
            <el-breadcrumb-item :to="{ path: '/AdminHome' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/SystemSetting/FormSetting' }">分类管理</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/SystemSetting/FormSettingAttriBute/AttriBute' }">属性列表</el-breadcrumb-item>
            <el-breadcrumb-item>{{ this.$route.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="card">
            <div class="card-header">
              填写字段信息
            </div>
            <div class="card-body">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="180px">
                    <div class="info-ruleForm">
                        <el-form-item label="字段名称" prop="formName">
                            <el-input v-model="ruleForm.formName"></el-input>
                        </el-form-item>
      
                         <el-form-item label="属性是否默认显示">
                            <el-radio-group v-model="ruleForm.isShow">
                                <el-radio label="show">显示</el-radio>
                                <el-radio label="hidden">隐藏</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="属性是否可选">
                            <el-radio-group v-model="ruleForm.domName">
                                <el-radio label="input">唯一属性</el-radio>
                                <el-radio label="radio">单选属性</el-radio>
                                <el-radio label="checkbox">复选属性</el-radio>
                            </el-radio-group>
                            <p class="tips">选择"单选/复选属性"时，可以该分类设置多个值。选择"唯一属性"时，该分类资产的该属性值只能设置一个值。</p>
                        </el-form-item>
                        <el-form-item label="该属性值的录入方式">
                            <el-input :disabled="ruleForm.domName=='input'" type="textarea" v-model="ruleForm.optionalValue" placeholder="多个值,请输入 ';(英文分号)' 隔开"></el-input>
                        </el-form-item>
                    </div>
                    <hr>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit('ruleForm')" :disabled="disabled">立即保存</el-button>
                        <el-button @click="goBack">返回</el-button>
                    </el-form-item>
                </el-form>                
            </div>
        </div>
        {{ ruleForm }}
    </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "AttrCreate",
  data() {
    return {
      disabled:false,
      ruleForm: {
        isShow:"show",
        formName: "",
        domName: "input",
        optionalValue:"",
        sortId: this.$route.query.sortid,
        sortName: this.$route.query.sortname
      },
      rules: {
        propertyName: [
          { required: true, message: "请输入属性名称", trigger: "blur" },
          { min: 1, max: 15, message: "长度在 1 到 15 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    onSubmit(formName) {
      this.disabled = true;
      this.$refs[formName].validate(valid => {
        if (valid) {
          request({
            method: "post",
            url: this.$api.createSortProperty,
            data: this.ruleForm
          }).then(res => {
            this.$message.success("保存成功!");
            this.goBack();
          });
        } else {
          this.disabled = false;
          return false;
        }
      });
    },
    goBack() {
      this.$router.go(-1); //返回上一层
    }
  }
};
</script>

<style lang="less" scoped>
.info-ruleForm {
  width: 500px;
}
.tips {
  line-height: 1.5;
  font-size: 12px;
  color: #999;
}
</style>
